<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <style type="text/css">
        .container {
            width: 420px;
            height: 320px;
            min-height: 320px;
            max-height: 320px;
            position: absolute;
            top: 0;
            left: 0;
            bottom: 0;
            right: 0;
            margin: auto;
            padding: 20px;
            z-index: 130;
            border-radius: 8px;
            background-color: #fff;
            box-shadow: 0 3px 18px rgba(100, 0, 0, .5);
            font-size: 16px;
        }

        .close {
            background-color: white;
            border: none;
            font-size: 18px;
            margin-left: 410px;
            margin-top: -10px;
        }

        .layui-input {
            border-radius: 5px;
            width: 300px;
            height: 40px;
            font-size: 15px;
        }

        .layui-form-item {
            margin-left: -20px;
        }

        #logoid {
            margin-top: -16px;
            padding-left: 150px;
            padding-bottom: 15px;
        }

        .layui-btn {
            margin-left: -50px;
            border-radius: 5px;
            width: 350px;
            height: 40px;
            font-size: 15px;
        }

        .verity {
            width: 120px;
        }

        .font-set {
            font-size: 13px;
            text-decoration: none;
            margin-left: 120px;
        }

        a:hover {
            text-decoration: underline;
        }

    </style>
    <link rel="stylesheet" href="/Layui/layui/css/layui.css">
</head>
<body class="layui-layout-body">
<div id="changePassword" style="display: none; padding: 10px">
    <form class="layui-form" action="" lay-filter="roomdata" method="post" id="roomdata">
        <div class="layui-form-item">
            <label class="layui-form-label">用户名</label>
            <div class="layui-input-block">
                <input type="text" name="username" required lay-verify="username" placeholder="请输入用户名"
                       autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">密码</label>
            <div class="layui-input-inline">
                <input type="password" name="password" required lay-verify="password" placeholder="请输入密码"
                       autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">姓名</label>
            <div class="layui-input-inline">
                <input type="text" name="name" required lay-verify="username" placeholder="请输入姓名"
                       autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">性别</label>
            <div class="layui-input-block">
                <input type="radio" name="sex" value="男" title="男">
                <input type="radio" name="sex" value="女" title="女" checked>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">年龄</label>
            <div class="layui-input-inline">
                <input type="number" name="age" required lay-verify="age" placeholder="输入年龄"
                       autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">班级</label>
            <div class="layui-input-inline">
                <input type="text" name="dept" required lay-verify="username" placeholder="输入班級"
                       autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button type="button" lay-submit="" lay-filter="demo1">立即注册</button>
                <button type="reset">重置</button>
            </div>
        </div>
    </form>
</div>
<div class="container">
    <form class="layui-form" action="/login" method="post">

        <div class="layui-form-item">
            <label class="layui-form-label">用户名</label>
            <div class="layui-input-block">
                <input type="text" name="title" required lay-verify="required" placeholder="请输入用户名" autocomplete="off"
                       class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">密 &nbsp;&nbsp;码</label>
            <div class="layui-input-inline">
                <input type="password" name="password" required lay-verify="required" placeholder="请输入密码"
                       autocomplete="off" class="layui-input">
            </div>
        </div>
        <div style="padding-left: 66px">
            <input type="checkbox" name="isRememberMe" value="1"/> 记住我
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button type="submit" class="layui-btn" lay-submit lay-filter="formDemo">登录</button>
            </div>
        </div>
    </form>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button id="reg" class="layui-btn">注册</button>
        </div>
    </div>
</div>
<script src="/Layui/layui/layui.js"></script>
<script src="/js/jquery-3.4.1.js"></script>
<script>
    layui.use(['jquery', 'form', 'layer'], function () {
        var form = layui.form;
        var layer = layui.layer;
        var $ = layui.jquery;
        //自定义验证规则
        form.verify({
            username: function (value) {
                if (value.length < 1 || value.length > 13) {
                    return '格式输入不正确';
                }
            },
            password: function (value) {
                if (value.length < 1 || value.length > 9) {
                    return '格式输入不正确';
                }
            },
            age: function (value) {
                if (value < 1 || value > 130) {
                    return '格式输入不正确';
                }
            },
        });
        //注册
        form.on('submit(demo1)', function (data) {
            var formObject = {};
            var formArray =$("#roomdata").serializeArray();
            $.each(formArray,function(i,item){
                formObject[item.name] = item.value;
            });
            //向后台发送数据
            $.ajax({
                type: 'POST',
                dataType: "json",
                url: '/reg',
                headers: {
                    'Content-Type': 'application/json'
                },
                data: JSON.stringify(formObject),
                success: function (vc) {
                    layer.closeAll();
                    alert("成功");
                },
                error: function (err) {
                    alert("失败");
                },
            });
            return false;
        });
        //修改密码
        $("#reg").click(function () {
            mainindex = layer.open({
                type: 1, //设置类别 默认为0，1页面层，2ifream层
                title: "注册", //提示
                content: $("#changePassword"),//内容
                skin: 'layui-layer-molv',//皮肤
                area: ['500px', '500px'],//宽高
                icon: 2           //只对type=0有效
                , shadeClose: true //点击遮罩是否关闭弹窗
                , anim: 1        //设置动画
                , maxmin: true    //是否显示最大化最小化
                , success: function (layero, index) {//layero,index两个好像是必须的，index点击次数
                      form.val("data", data);
                }
            });
        });
    });
</script>
</body>
</html>